package com.mfnote.view.paint;

import com.mfnote.view.R;
import com.mfnote.view.R.anim;
import com.mfnote.view.R.id;
import com.mfnote.view.R.layout;
import com.mfnote.view.other.MyApplication;
import com.mfnote.view.paint.NewPaintActivity;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
import android.widget.LinearLayout;

public class NewPaintActivity extends Activity {

	LinearLayout ll_paintboard=null; //设置画布
	public static NewPaintActivity instance=null; //创建实例
	PaintView paintView; //声明PaintView对象
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newpaint);
		MyApplication.getInstance().addActivity(this); //加入Activity集合
		
		instance=this;
	}
	
	/** 获取用户焦点并设置画布 **/
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		
		ll_paintboard=(LinearLayout) findViewById(R.id.ll_paintboard);
		ll_paintboard.removeAllViews();
		paintView =new PaintView(this,ll_paintboard.getWidth(),ll_paintboard.getHeight());
		ll_paintboard.addView(paintView);
	}

	/** 按键监听 **/
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK) { //捕获Back按键
			
			Intent intent = new Intent(NewPaintActivity.this,PaintActivity.class);
			startActivity(intent);
			this.finish();
			overridePendingTransition(R.anim.push_left_in,
					R.anim.push_right_out);
		}
		return true;
	}
}
